//
//  CellForAds.m
//  MY Project For Sport
//
//  Created by dllo on 16/1/26.
//  Copyright © 2016年 dilo. All rights reserved.
//

#import "CellForAds.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import "ModelForHotNews.h"
#import <DKNightVersion.h>
#import "UIColor+Wonderful.h"

#define WEIGHTT [UIScreen mainScreen].bounds.size.width / 375
#define HEIGHTT [UIScreen mainScreen].bounds.size.height / 667


@interface CellForAds ()
@property (nonatomic, retain) UILabel *labelForAds;
@property (nonatomic, retain) UILabel *labelForFoot;
@property (nonatomic, retain) UIView *view;
@end

@implementation CellForAds

- (void)dealloc {
    [_labelForAds release];
    [_labelForFoot release];
    [_imageForAds release];
    [_view release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.contentView.dk_backgroundColorPicker = DKColorWithColors([UIColor linenColor], [UIColor grayColor]);
        
        [self createSubview];
        
    }
    return self;
    
}

- (void)createSubview {

    self.view = [[UIView alloc] init];
    [self.contentView addSubview:self.view];
    [_view release];

    self.imageForAds = [[UIImageView alloc] init];
    [self.contentView addSubview:self.imageForAds];
    [_imageForAds release];
    
    self.labelForAds = [[UILabel alloc] init];
    [self.contentView addSubview:self.labelForAds];
    [_labelForAds release];
    
    self.labelForFoot = [[UILabel alloc] init];
    [self.contentView addSubview:self.labelForFoot];
    [_labelForFoot release];
    
    

}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    self.view.frame = CGRectMake(2, 5, self.contentView.frame.size.width - 4, self.contentView.frame.size.height - 10);
    //self.view.backgroundColor = [UIColor whiteColor];
    self.view.dk_backgroundColorPicker = DKColorWithRGB (0xffffff, 0x343434);
    
    self.labelForAds.numberOfLines = 0;
    self.labelForAds.font = [UIFont systemFontOfSize:19];
    self.labelForAds.frame = CGRectMake(self.contentView.frame.size.width / 4 + 10 * WEIGHTT, 5 * HEIGHTT, self.contentView.frame.size.width - self.contentView.frame.size.width / 4 - 15 * WEIGHTT, (self.contentView.frame.size.height - 15 * HEIGHTT) / 2);
    self.labelForAds.dk_textColorPicker = DKColorWithColors([UIColor whiteColor], [UIColor whiteColor]);
    
    self.labelForFoot.frame = CGRectMake(self.contentView.frame.size.width / 8 * 7, self.contentView.frame.size.height / 4 * 3, self.contentView.frame.size.width / 8, self.contentView.frame.size.width / 18);
    self.labelForFoot.font = [UIFont systemFontOfSize:14];

    self.labelForFoot.textColor = [UIColor orangeColor];
    self.labelForFoot.text = @"广告";
    
    self.imageForAds.frame = CGRectMake(2 * WEIGHTT, 5 * HEIGHTT, self.contentView.frame.size.width -  4 * WEIGHTT, self.contentView.frame.size.height - 10 * HEIGHTT);
 
    
}

- (void)passModelForHotNews:(ModelForHotNews *)model {

    self.labelForAds.text = model.title;
    self.labelForAds.textAlignment = NSTextAlignmentCenter;
  
    [self.imageForAds sd_setImageWithURL:[NSURL URLWithString:model.u]];
    
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
